package SystemDataTypes;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class FlightState {

	public int flightId;
	public String state;
	public String type;
	
	FlightState(int flightId, String state, String type)
	{
		this.flightId = flightId;
		this.state = state;
		this.type = type;
	}
	
	public FlightState()
	{
	}

	FlightState(JSONObject obj)
	{
		if (obj.has("FlightState")) 
		{
	        try {
				JSONObject data = obj.getJSONObject("FlightState");				
				this.flightId = data.getInt("flightId");
				this.state = data.getString("state");
				this.type = data.getString("type");
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
	}
	
	public String toJSONString()
	{
        JSONObject container = new JSONObject();       
        JSONObject data = new JSONObject();              
        try {
            data.put("flightId", this.flightId);
            data.put("state", this.state);
            data.put("type", this.type);
            container.put("FlightState", data);	            
        } catch (JSONException ex) {
            Logger.getLogger(FlightData.class.getName()).log(Level.SEVERE, null, ex);
        }	        
        return container.toString();
	}
}
